package demo2;

import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description: 删除有序数组中的重复项
 * User: liangyuanzhang
 * Date: 2025-3-12
 * Time: 18:21
 */
class Soution{
    public int removeDupolicates(int[] nums){
        int n = nums.length;
        int j = 0;
        for (int i = 0; i < n; i++) {
            if (nums[j] != nums[i]){
                nums[++j] = nums[i];
            }
        }
        return j + 1;
    }
}
public class Test {
    public static void main(String[] args) {
        Soution soution = new Soution();
        int[] array = {1,1,2};
        int ret = soution.removeDupolicates(array);
        int[] arr = Arrays.copyOf(array,ret);
        System.out.println(Arrays.toString(arr));
    }
}
